package com.example.myapplication;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

public class MainActivity3 extends AppCompatActivity {
    Handler handler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);

        Intent intent = getIntent();
        TextView textView2 = findViewById(R.id.textView2);
        TextView textView13 = findViewById(R.id.textView13);
        TextView textView14 = findViewById(R.id.textView14);
        String jhkk = intent.getStringExtra("sf");
        String asdsa = intent.getStringExtra("wsdac");
        String qwerr = intent.getStringExtra("dfsf");

        Gson gson = new Gson();
        RecyclerView recyclerView = findViewById(R.id.asd);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(MainActivity3.this, LinearLayoutManager.VERTICAL, false);
//        GridLayoutManager gridLayoutManager = new GridLayoutManager(MainActivity3.this, 1);
        handler = new Handler() {
            @Override
            public void handleMessage(@NonNull Message msg) {
                super.handleMessage(msg);
                Log.i("tag", "22222");
                String response = msg.obj.toString();
                LiebieoaJiekou liebieoaJiekou = gson.fromJson(response, LiebieoaJiekou.class);
                recyclerView.setLayoutManager(linearLayoutManager);
//                recyclerView.setLayoutManager(gridLayoutManager);
                Liebiao liebiao = new Liebiao(liebieoaJiekou.getData().list);
                recyclerView.setAdapter(liebiao);
            }
        };


        new util().POST("https://photo.vshare.site/online/test/lists", "9154zDE3HAFVFxLTJiOGhYg5y4k19F7rqVPpDWKMLw", "{\"from\":\""+jhkk+"\",\"to\":\""+asdsa+"\",\"date\":\""+qwerr+"\",\"type\":1}", handler);

        ImageView imageView4 = findViewById(R.id.imageView4);
        imageView4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity3.this, MainActivity2.class);
                startActivity(intent);
            }
        });



        textView2.setText(jhkk);
        textView13.setText(asdsa);
        textView14.setText(qwerr);
    }
//    public  static  void  main(String[] args){
//        List<String> dataStings = new ArrayList<>();
//        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd");
//        List<Date> dates = new ArrayList<>();
//        for (String datesting : dataStings){
//            try {
//                dates.add(sdf.parse(datesting));
//            }catch (ParseException e){
//                e.printStackTrace();
//            }
//        }
//        Collections.sort(dates, new Comparator<Date>() {
//            @Override
//            public int compare(Date o1, Date o2) {
//                return o1.compareTo(o2);
//            }
//        });
//        for (Date date : dates){
//            System.out.println(sdf.format(date));
//        }
//    }
}